﻿using System.Workflow.ComponentModel;
using System.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel.Design;
using System;
using System.Collections.Generic;
using System.Workflow.ComponentModel.Compiler;

using BPM.Base.WFLib;

namespace BPM.Base.WFLib.CustomerAttribute
{
    class WaitSubmitTemplateValidator : System.Workflow.ComponentModel.Compiler.ActivityValidator
    {
        public override ValidationErrorCollection ValidateProperties(ValidationManager manager, object obj)
        {
            ValidationErrorCollection Errors = base.ValidateProperties(manager, obj);

            Activity t = obj as Activity;

            if (t != null)
            {
                if (t.Parent !=null )
                {
                    this.PropertyValidator(Errors, t);
                }
            }
            return Errors;
        }

        private void PropertyValidator(ValidationErrorCollection Errors, object obj)
        {
            if (obj is 等待提交)
            {
                等待提交 activity = obj as 等待提交;


                if (string.IsNullOrEmpty(activity.状态名称))
                {
                    Errors.Add(ValidationError.GetNotSetValidationError(等待提交.状态名称Property.Name));
                }

                CheckProcessType(activity, Errors);


            }

        }

        /// <summary>
        /// 验证处理方式
        /// </summary>
        /// <param name="activity"></param>
        /// <param name="errors"></param>
        private void CheckProcessType(等待提交 activity,ValidationErrorCollection errors)
        {
            if (!string.IsNullOrEmpty(activity.处理方式))
            {
                switch (activity.处理方式)
                {
                    #region 到人
                    case "到人":
                        if(string.IsNullOrEmpty(activity.办理人员))
                        {
                            errors.Add(ValidationError.GetNotSetValidationError(等待提交.办理人员Property.Name));
                            break;
                        }
                        else if
                            (
                            !string.IsNullOrEmpty(activity.接件部门) || !string.IsNullOrEmpty(activity.接件职能)
                            ||!string.IsNullOrEmpty(activity.接件时特殊权限)||(activity.接件时限!=0)
                            || !string.IsNullOrEmpty(activity.接件超时操作) 
                            || !string.IsNullOrEmpty(activity.分配部门) || !string.IsNullOrEmpty(activity.分配职能)
                            || !string.IsNullOrEmpty(activity.分配人员) || !string.IsNullOrEmpty(activity.分配时特殊权限)
                            || (activity.分配时限!=0) || !string.IsNullOrEmpty(activity.分配超时操作 )
                                )
                        {
                            errors.Add(ValidationError.GetNotSetValidationError("请查看处理方式为到 人 的规则"));
                            break;
                        }
                       

                        break;
                    #endregion

                    #region 组接件
                    case "组接件":
                        if (string.IsNullOrEmpty(activity.接件部门))
                        {
                            errors.Add(ValidationError.GetNotSetValidationError(等待提交.接件部门Property.Name));
                            break;
                        }
                        else if(string.IsNullOrEmpty(activity.接件职能))
                        {
                            errors.Add(ValidationError.GetNotSetValidationError(等待提交.接件职能Property.Name));
                            break;
                        }
                        else if
                           (
                           !string.IsNullOrEmpty(activity.办理人员)
                           
                           || !string.IsNullOrEmpty(activity.分配部门) || !string.IsNullOrEmpty(activity.分配职能)
                           || !string.IsNullOrEmpty(activity.分配人员) || !string.IsNullOrEmpty(activity.分配时特殊权限)
                           || (activity.分配时限 != 0) || !string.IsNullOrEmpty(activity.分配超时操作)
                               )
                        {
                            errors.Add(ValidationError.GetNotSetValidationError("请查看处理方式为 组接件 的规则"));
                            break;
                        }


                        break;

                    #endregion

                    #region 组分配
                    case "组分配":
                        if (string.IsNullOrEmpty(activity.分配部门))
                        {
                            errors.Add(ValidationError.GetNotSetValidationError(等待提交.分配部门Property.Name));
                            break;
                        }
                        else if (string.IsNullOrEmpty(activity.分配职能))
                        {
                            errors.Add(ValidationError.GetNotSetValidationError(等待提交.分配职能Property.Name ));
                            break;
                        }
                      
                        break;

                    #endregion

                    #region 组接件组分配
                    case "组接件组分配":
                        if (string.IsNullOrEmpty(activity.接件部门))
                        {
                            errors.Add(ValidationError.GetNotSetValidationError(等待提交.接件部门Property.Name));
                            break;
                        }
                        else if (string.IsNullOrEmpty(activity.接件职能))
                        {
                            errors.Add(ValidationError.GetNotSetValidationError(等待提交.接件职能Property.Name ));
                            break;
                        }
                        else if (string.IsNullOrEmpty(activity.分配部门))
                        {
                            errors.Add(ValidationError.GetNotSetValidationError(等待提交.分配部门Property.Name));
                            break;
                        }
                        else if (string.IsNullOrEmpty(activity.分配职能))
                        {
                            errors.Add(ValidationError.GetNotSetValidationError(等待提交.分配职能Property.Name));
                            break;
                        }
                        else if( !string.IsNullOrEmpty(activity.办理人员))
                        {
                            errors.Add(ValidationError.GetNotSetValidationError("请查看处理方式为 组接件组分配 的规则"));
                            break;
                        }

                        break;
                    #endregion

                    #region 系统处理
                    case "系统处理":
                        break;
                    #endregion

                    default:
                        break;
                }
            }
        }



    }
	
}
